<?php

namespace App\Http\Controllers\Admin;

use App\admin\Admin;
use App\admin\Adlog;
use App\Http\Controllers\Admin\LogHander;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

class LoginController extends BaseController
{
	//登录页面
	public function index()
	{
		return view('admin.login');
	}
	//登录页面登录功能
	public function loginUp(Request $request)
	{
//		$request->session()->forget('adminBackSet');return;
//		echo '-------';
//		echo $request->session()->get('adminBackSet');
//		$request->session()->put('adminBackSet', $email);
//		echo session('adminBackSet');
//		echo '-------';return;
//		return;

		$value = $request->session()->get('adminBackSet');
		if (!empty($value)) {
			$request->session()->forget('adminBackSet');
		}
		
		$email=$request->input('myname');
		$pwd=$request->input('password');
		if(empty($email) || empty($pwd)){
			return redirect()->back();
		}
		$ppwd = md5($pwd);
		//对比，表中存在才会跳
		$flight_ = new Admin;
		$flights = $flight_->where('email', $email)->get();
		$cnum = count($flights);
//		echo $ppwd.'<br/>';
//		echo $email.'<br/>'.'<br/>';
//		echo $flights[0]["password"].'<br/>';
//		echo $flights[0]["email"];
		if($cnum == 1){
			if($flights[0]["email"] == $email && $ppwd == $flights[0]["password"]){
				$request->session()->put('adminBackSet', $email);
				$request->session()->put('adminBackName', $flights[0]["name"]);
				//日志增加
				$cars=array('name'=>$email,'info'=>'adminLogin','cnt'=>'adminLogin');
				$temp = new LogHander;
				$temp->logs($cars);
				//去到首页面
				return redirect('admincp');
			}
		}
		return redirect()->back();
		//return redirect()->action('Admin\IndexController@index');
//		return redirect('admincp');
	}
	public function loginOut(Request $request){
//		Request $request = new request();
		$request->session()->forget('adminBackSet');
		$request->session()->forget('adminBackName');
		return redirect('logincp');
	}
	//登录页面登录功能
	public function registerUp()
	{
		return "registerUp";
	}
	public function forgetPwdUp()
	{
		return "forgetPwdUp";
	}
}
